/////////////////////////////////////////////////////////////////////////////
// Name:        ax_menu_shortcuts.h
// Purpose:     Shortcut settings menu class
// Author:      Julian Smart
// Modified by:
// Created:     2009-03-20
// RCS-ID:
// Copyright:   (c) Julian Smart
// Licence:     New BSD License
/////////////////////////////////////////////////////////////////////////////

#ifndef _AX_MENU_SHORTCUTS_H_
#define _AX_MENU_SHORTCUTS_H_

/*
 * Includes
 */

#include "ax/ax_activator.h"
#include "ax/ax_menu_text.h"

class AxSpeech;
class wxShortcutManager;
class wxShortcutItem;

/**
    @class AxShortcutsMenuItem

    @category{ax}
 */

class AxShortcutsMenuItem: public AxMenuItem
{
    DECLARE_CLASS( AxShortcutsMenuItem )
    DECLARE_EVENT_TABLE( )

    friend class AxShortcutTextActivator;

public:
// Constructors

    AxShortcutsMenuItem(const AxShortcutsMenuItem& item)
    {
        Copy(item);
    }
    /// Pass menu controller, speech pointer, shortcut manager, window whose
    /// shortcuts should be updated, and an optional menubar whose labels should
    /// be updated.
    AxShortcutsMenuItem(AxMenuController* controller, AxSpeech* speech,
        wxShortcutManager* manager, wxWindow* window, wxMenuBar* menuBar = NULL);

    void Copy(const AxShortcutsMenuItem& item)
    {
        AxMenuItem::Copy(item);

        m_speech = item.m_speech;
        m_controller = item.m_controller;
        m_shortcutManager = item.m_shortcutManager;
        m_window = item.m_window;
        m_menuBar = item.m_menuBar;
    }

    void OnChangeShortcut(wxCommandEvent& event);

    void UpdateShortcuts();

    virtual AxMenuItem* Clone() { return new AxShortcutsMenuItem(* this); }

protected:
    AxSpeech*           m_speech;
    AxMenuController*   m_controller;
    wxShortcutManager*  m_shortcutManager;
    wxWindow*           m_window;
    wxMenuBar*          m_menuBar;
};

/**
    @class AxShortcutsActivator

    Top-level item activator for the shortcut settings,
    creating the actual menu on demand.

    @category{ax}

 */

class AxShortcutsActivator: public AxActivator
{
public:
    
    DECLARE_DYNAMIC_CLASS( AxShortcutsActivator )

public:
// Constructors

    AxShortcutsActivator() { Init(); }

    AxShortcutsActivator(AxSpeech* speech, wxShortcutManager* shortcutsManager)
    { m_speech = speech; m_shortcutManager = shortcutsManager; }

    AxShortcutsActivator(const AxShortcutsActivator& activator) { Init(); Copy(activator); }

    void Init() { m_speech = NULL; m_shortcutManager = NULL; }

    void Copy(const AxShortcutsActivator& activator)
    {
        AxActivator::Copy(activator);
        m_speech = activator.m_speech;
        m_shortcutManager = activator.m_shortcutManager;
    }

    virtual AxActivator* Clone() const { return new AxShortcutsActivator(* this); }

    /// Called when the user activates a menu item by pressing return or double-clicking
    virtual AxMenu* Activate(AxMenuController* controller, AxMenuItem* item);

protected:
    AxSpeech*           m_speech;
    wxShortcutManager*  m_shortcutManager;
};

/**
    @class AxShortcutTextActivator

    Used by AxShortcutsMenuItem, as the per-shortcut activator.

    @category{ax}
 */

class AxShortcutTextActivator: public AxTextActivator
{
public:
    
    DECLARE_DYNAMIC_CLASS( AxShortcutTextActivator )

public:
    typedef enum 
    {
        AxShortcutCommandUnknown,
        AxShortcutCommandShortcut,
        AxShortcutCommandReset
            
    } AxShortcutCommand;

// Constructors

    AxShortcutTextActivator() { Init(); }

    AxShortcutTextActivator(
        AxShortcutCommand command,
        const wxString& labelSpec,
        const wxString& descriptionSpec,
        wxShortcutManager* shortcutManager,
        AxSpeech* speech,
        wxShortcutItem* shortcut);

    AxShortcutTextActivator(const AxShortcutTextActivator& activator) { Init(); Copy(activator); }

    void Init();

    void Copy(const AxShortcutTextActivator& activator);

    virtual AxActivator* Clone() const { return new AxShortcutTextActivator(* this); }

    /// Called when the user activates a menu item by pressing return or double-clicking
    virtual AxMenu* Activate(AxMenuController* controller, AxMenuItem* item);

protected:

    AxSpeech*           m_speech;
    wxShortcutManager*  m_shortcutManager;
    wxShortcutItem*     m_shortcut;
    AxShortcutCommand   m_command;
};

#endif
    // _AX_MENU_SHORTCUTS_H_
